package com.minelx.sqlstructures.core.values;

import java.util.Objects;

public class FieldValues {
	private final int index;

	private final String name;

	private final String type;

	private final String comment;

	private final boolean isPrimary;

	public FieldValues(int index, String name, String type, String comment, boolean isPrimary) {
		this.index = index;
		this.name = name;
		this.type = type;
		this.comment = comment;
		this.isPrimary = isPrimary;
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) return true;
		if (o == null || getClass() != o.getClass()) return false;
		FieldValues that = (FieldValues) o;
		return index == that.index && isPrimary == that.isPrimary && name.equals(that.name) && type.equals(that.type) && comment.equals(that.comment);
	}

	@Override
	public int hashCode() {
		return Objects.hash(index, name, type, comment, isPrimary);
	}

	public String representSql() {
		if (isPrimary()) {
			return getName() + " " + getType() + " PRIMARY KEY AUTO_INCREMENT";
		}
		return getName() + " " + getType();
	}

	public int getIndex() {
		return index;
	}

	public String getName() {
		return name;
	}

	public String getType() {
		return type;
	}

	public String getComment() {
		return comment;
	}

	public boolean isPrimary() {
		return isPrimary;
	}

	@Override
	public String toString() {
		return "FieldDTO{" +
				"index=" + index +
				", name='" + name + '\'' +
				", type='" + type + '\'' +
				", comment='" + comment + '\'' +
				", isPrimary=" + isPrimary +
				'}';
	}
}
